'use strict';
module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('users', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      username: {
        type: Sequelize.STRING(20),
        allowNull: false
      },
      password: {
        type: Sequelize.CHAR(32),
        allowNull: false
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    }, {
      charset: 'utf8mb4',
      collate: "utf8mb4_bin"
    });
    await queryInterface.addIndex('users', {
      name: "username",
      unique: true,   // 不允许重复
      fields: ['username']
    })
  },
  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('users', []);
  }
};